﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MashGen.Engine.Expressions
{
    public class Variable : AbstractExpression
    {
        public string Name { get; private set; }

        public Variable(string name)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            Name = name.Trim();
        }

        public override R Vist<R, P>(IExpressionVisitor<R, P> visitor, P parameter = default(P))
        {
            return visitor.VisitVariable(this, parameter);
        }

        public override bool Equals(AbstractExpression other)
        {
            var otherVariable = other as Variable;
            if (ReferenceEquals(otherVariable, null))
            {
                return false;
            }
            return Name.Equals(otherVariable.Name);
        }

        public override int GetHashCode()
        {
            return Name.GetHashCode();
        }
    }
}
